package com.jwdf.uda.http.action;

import android.content.Context;
import android.support.annotation.NonNull;
import android.text.TextUtils;

import com.jwdf.uda.bean.PbBean;
import com.jwdf.uda.http.AHttpService;
import com.jwdf.uda.http.ApiService;

import retrofit2.Call;

/**
 * Created by Administrator on 2016/9/1.
 */
public class QuizIndexAction extends AHttpService<PbBean.PbResQuestionQuestionList> {
    private int offset;
    private PbBean.PbSignBaseQuestionType type = PbBean.PbSignBaseQuestionType.QUESTION_INDEX_NONE;
    private int code = 0;
    private String id;

    public QuizIndexAction(Context context) {
        super(context);
    }

    public QuizIndexAction(Context context, int offset) {
        super(context);
        this.offset = offset;
    }

    public QuizIndexAction(Context context, int offset, PbBean.PbSignBaseQuestionType type) {
        super(context);
        this.type = type;
        this.offset = offset;
    }

    public QuizIndexAction(Context context, int offset, int code) {
        super(context);
        this.code = code;
        this.offset = offset;
    }

    public QuizIndexAction(Context context, int offset, int code, String id, PbBean.PbSignBaseQuestionType type) {
        super(context);
        this.id = id;
        this.type = type;
        this.offset = offset;
        this.code = code;
    }

    @NonNull
    public static QuizIndexAction newInstance(Context context) {
        return new QuizIndexAction(context);
    }

    @NonNull
    public static QuizIndexAction newInstance(Context context, int offset) {
        return new QuizIndexAction(context, offset);
    }

    @NonNull
    public static QuizIndexAction newInstance(Context context, int offset, PbBean.PbSignBaseQuestionType type) {
        return new QuizIndexAction(context, offset, type);
    }

    @NonNull
    public static QuizIndexAction newInstance(Context context, int offset, int code) {
        return new QuizIndexAction(context, offset, code);
    }

    @NonNull
    public static QuizIndexAction newInstance(Context context, int offset, int category, String id, PbBean.PbSignBaseQuestionType type) {
        return new QuizIndexAction(context, offset, category, id, type);
    }

    @Override
    protected Call newRetrofitCall(ApiService apiService, PbBean.PbBaseClientInfo.Builder baseBuilder) {
        PbBean.PbReqQuestionQuestionList.Builder builder = PbBean.PbReqQuestionQuestionList.newBuilder();
        builder.setBaseClientInfo(baseBuilder);
        builder.setQuestionType(type);
        builder.setCategoryCode(code);

        if(offset != 0)
            builder.setOffset(offset);

        if(!TextUtils.isEmpty(id))
            builder.setUserId(id);

        return apiService.getQuizList(builder.build());
    }
}
